package com.uls.web.controller.hj;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.uls.framework.config.MinioProp;
import com.uls.framework.utils.MinioUtils;
import com.uls.hj.vo.VenueCountVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.uls.common.annotation.Log;
import com.uls.common.core.controller.BaseController;
import com.uls.common.core.domain.AjaxResult;
import com.uls.common.enums.BusinessType;
import com.uls.hj.domain.HjVenues;
import com.uls.hj.service.IHjVenuesService;
import com.uls.common.utils.poi.ExcelUtil;
import com.uls.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 场馆Controller
 * 
 * @author hj
 * @date 2024-11-07
 */
@RestController
@RequestMapping("/hj/venues")
public class HjVenuesController extends BaseController
{
    @Autowired
    private IHjVenuesService hjVenuesService;

    @Autowired
    private MinioUtils minioUtils;

    @Autowired
    private MinioProp minioProp;

    /**
     * 查询场馆列表
     */
    @PreAuthorize("@ss.hasPermi('hj:venues:list')")
    @GetMapping("/list")
    public TableDataInfo list(HjVenues hjVenues)
    {
        startPage();
        List<HjVenues> list = hjVenuesService.selectHjVenuesList(hjVenues);
        return getDataTable(list);
    }

    /**
     * 导出场馆列表
     */
    @PreAuthorize("@ss.hasPermi('hj:venues:export')")
    @Log(title = "场馆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HjVenues hjVenues)
    {
        List<HjVenues> list = hjVenuesService.selectHjVenuesList(hjVenues);
        ExcelUtil<HjVenues> util = new ExcelUtil<HjVenues>(HjVenues.class);
        util.exportExcel(response, list, "场馆数据");
    }

    /**
     * 获取场馆详细信息
     */
    @PreAuthorize("@ss.hasPermi('hj:venues:query')")
    @GetMapping(value = "/{venueId}")
    public AjaxResult getInfo(@PathVariable("venueId") Long venueId)
    {
        return success(hjVenuesService.selectHjVenuesByVenueId(venueId));
    }

    /**
     * 新增场馆
     */
    @PreAuthorize("@ss.hasPermi('hj:venues:add')")
    @Log(title = "场馆", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HjVenues hjVenues)
    {
        return toAjax(hjVenuesService.insertHjVenues(hjVenues));
    }

    /**
     * 修改场馆
     */
    @PreAuthorize("@ss.hasPermi('hj:venues:edit')")
    @Log(title = "场馆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HjVenues hjVenues)
    {
        return toAjax(hjVenuesService.updateHjVenues(hjVenues));
    }

    /**
     * 删除场馆
     */
    @PreAuthorize("@ss.hasPermi('hj:venues:remove')")
    @Log(title = "场馆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{venueIds}")
    public AjaxResult remove(@PathVariable Long[] venueIds)
    {
        return toAjax(hjVenuesService.deleteHjVenuesByVenueIds(venueIds));
    }

    /**
     * 上传
     *
     * @param file
     * @param request
     * @return
     */
    @PostMapping("/uploadMinio")
    public String uploadMinio(@RequestParam(name = "file", required = false) MultipartFile file, HttpServletRequest request) {
        JSONObject res = null;
        try {
            res = minioUtils.uploadFile(file, minioProp.getBucket());
        } catch (Exception e) {
            e.printStackTrace();
            res.put("code", 0);
            res.put("msg", "上传失败");
        }
        return res.toJSONString();
    }

    @GetMapping("/getVenuesBystatus")
    public AjaxResult getVenuesBystatus()
    {
        List<HjVenues> list = hjVenuesService.selectHjVenuesListByStatus(1);
        return success(list);
    }

    @GetMapping("/getAllVenues")
    public AjaxResult getAllVenues()
    {
        List<HjVenues> list = hjVenuesService.selectHjVenuesList(null);
        return success(list);
    }

    @GetMapping("/countSchedule")
    public AjaxResult countSchedule(){
        List<VenueCountVo> list = hjVenuesService.countSchedule();
        return success(list);
    }


}
